<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Ke</title>
	<link type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/themes/sunny/jquery-ui.css" rel="Stylesheet"/>

	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js"></script>
	<script type="text/javascript">
		$(function (){
			$('#loginInfo').load("auth/jopenid/me.nut");
			$('#login').button();
			$('#logout').button();
			Z.forum.loadTips();
			Z.wiki.loadWikis();
			$('#tabs').tabs({ fx: { opacity: 'toggle' } });
		});
		
		var Z = new Object();
		Z.login = function () {
			window.location = "auth/jopenid/login.nut";
		}
		Z.logout = function () {
			$.get("auth/jopenid/logout.nut");
			$('#loginInfo').load("auth/jopenid/me.nut");
		}
		//Forum 论坛
		
		Z.forum = new Object();
		Z.forum.currentPage = 1;
		Z.forum.currentTipId = -1;
		Z.forum.currentPageSize = 10;

		Z.forum.loadTips = function () {
			$("#mainInfo").load("f/list.nut",{page : Z.forum.currentPage ,pageSize : Z.forum.currentPageSize });
		}

		Z.forum.nextPage = function (){
			if (Z.forum.currentPage > 0 ) {
				Z.forum.currentPage = Z.forum.currentPage + 1;
			} else {
				Z.forum.currentPage = 1;
			}
			Z.forum.loadTips();
		}
		Z.forum.prevPage = function (){
			if (Z.forum.currentPage > 2 ) {
				Z.forum.currentPage = Z.forum.currentPage - 1;
			} else {
				Z.forum.currentPage = 1;
			}
			Z.forum.loadTips();
		}
		Z.forum.firstPage = function (){
			Z.forum.currentPage = 1;
			Z.forum.loadTips();
		}
		Z.forum.lastPage = function (){
			Z.forum.currentPage = 1000000;
			Z.forum.loadTips();
		}
		Z.forum.viewTip = function (tipId) {
			Z.forum.currentTipId = tipId;
			$('#viewTip').load('f/viewTip.nut',{tipId : Z.forum.currentTipId});
			$('#tabs').tabs("select",1);
		}
		Z.forum.newTip = function (content) {
			$.post("f/newTip.nut",{content : content}, Z.forum.loadTips );
		}
		Z.forum.addComment = function (comment) {
			$.post("f/addComment.nut",{tipId : Z.forum.currentTipId , comment : comment}, function(){ Z.forum.viewTip(Z.forum.currentTipId); });
		}

		//Wiki
		Z.wiki = new Object();
		Z.wiki.loadWikis = function () {
			$("#wikis").load("wiki/list.nut",{page : Z.forum.currentPage ,pageSize : Z.forum.currentPageSize });
		}

		Z.wiki.create = function (form) {
			$.post("wiki/create",$(form).serialize(),function(data){
				$("#wikis").load("wiki/list.nut",{page : Z.forum.currentPage ,pageSize : Z.forum.currentPageSize });
			   });
		}
	</script>
</head>
<body>
	<!-- 登录信息 -->
	<div id="loginInfo"></div>
	<div id="tabs">
		<ul>
			<li><a href="#mainInfo">帖子列表</a></li>
			<li><a href="#viewTip">查看帖子</a></li>
			<li><a href="#wikis">Wiki</a></li>
		</ul>
		
		<!-- 主体 罗列帖子 -->
		<div id="mainInfo"></div>
		<!-- 某条帖子的详细页 -->
		<div id="viewTip"></div>
		<!-- 其他未定 -->
		<div id="wikis"></div>
	</div>
	<!-- 页脚 -->
	<div id="footInfo"></div>
</body>
</html>